# 尾部类别精度数据
categories = ['Gear Crack', 'Bearing Pitting', 'Shaft Misalignment']
fedprox_acc = [62.1, 58.7, 64.5]
dhaf_acc = [76.8, 78.2, 79.9]

x = np.arange(len(categories))
width = 0.35

plt.figure(figsize=(10, 6))
rects1 = plt.bar(x - width/2, fedprox_acc, width, label='FedProx', color='#FFBE7A')
rects2 = plt.bar(x + width/2, dhaf_acc, width, label='DHA-FL', color='#82B0D2')

# 添加数据标签
def autolabel(rects):
    for rect in rects:
        height = rect.get_height()
        plt.text(rect.get_x() + rect.get_width()/2, height+0.8,
                f'{height}%', ha='center', fontsize=10)
autolabel(rects1)
autolabel(rects2)

# # 标注提升幅度
# plt.text(0, 80, '↑14.7%', ha='center', fontsize=10)
# plt.text(1, 82, '↑19.5%', ha='center', fontsize=10)
# plt.text(2, 84, '↑15.4%', ha='center', fontsize=10)

plt.ylabel('Accuracy (%)', fontsize=14)
plt.xlabel('categories', fontsize=14)
plt.xticks(x, categories)
plt.ylim(50, 85)
# plt.title('Tail Category Recognition Performance (Frequency<5%)', fontsize=14)
plt.legend(loc='upper left',prop={'size': 14, 'family': 'SimHei'})
plt.grid(axis='y', alpha=0.3)
plt.savefig('tail_category_accuracy_en.png', bbox_inches='tight')
